﻿using System.Reflection;
using Pets;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace SpeciesTest
{
    
    
    /// <summary>
    ///This is a test class for PetFinderTest and is intended
    ///to contain all PetFinderTest Unit Tests
    ///</summary>
    [TestClass()]
    public class PetFinderTest
    {
        public static string GetEmbeddedResourse()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            string [] paths = assembly.GetManifestResourceNames();
            return paths.FirstOrDefault();
        }
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for FindAllMatches
        ///</summary>
        [TestMethod()]
        public void FindAllMatchesTest()
        {
            PetFinder finder = new PetFinder(PetFinderTest.GetEmbeddedResourse());
            Dictionary<string, List<string>> actual = finder.FindAllMatches();
            List<string> expected = new List<string>();
            expected.Add("dog");
            expected.Add("cat");
            expected.Add("parrot");
            int counter = 0;
            foreach (var item in actual.Keys)
            {

                Assert.AreEqual(expected[counter++], item);
            }
        }

        /// <summary>
        ///A test for WriteMatches
        ///</summary>
        [TestMethod()]
        public void WriteMatchesTest()
        {
            PetFinder finder = new PetFinder(PetFinderTest.GetEmbeddedResourse());
            IOrderedEnumerable<KeyValuePair<string,List<string>>> actual = finder.WriteMatches();
            List<string> expected = new List<string>();
            expected.Add("cat");
            expected.Add("dog");
            expected.Add("parrot");
            int counter = 0;
            foreach (var item in actual)
            {

                Assert.AreEqual(expected[counter++], item.Key);
            }
        }

        [TestMethod()]
        public void OpenFileTest() 
        {
            PetFinder finder = new PetFinder("dawdwa");
            finder.FindAllMatches();
        }
    }
}
